moved checks upon focus setting from gtk_window_real_set_focus to
authorTim Janik <timj@gtk.org>
Thu, 3 Dec 1998 06:52:48 +0000 (06:52 +0000)
committerTim Janik <timj@src.gnome.org>
Thu, 3 Dec 1998 06:52:48 +0000 (06:52 +0000)
Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>

        * gtk/gtkwindow.c: moved checks upon focus setting from
        gtk_window_real_set_focus to gtk_window_set_focus, so we don't
        emit the signal if unneccessary.

        * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
        containers when grabbing focus on a new widget. this is based on
        a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.

        * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
        flag, so we take the buttons into consideration upon the next focus
        request.

        * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
        assertment.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkclist.c
gtk/gtkcontainer.c
gtk/gtkwidget.c
gtk/gtkwindow.c

index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index 66dba6fc56b91cfce2bb17e38653bcfa16770a4b..f3097e17a1108a5e644c924de6bfb5f9e5599004 100644 (file)
@@ -1,3 +1,20 @@
+Thu Dec  3 06:20:59 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkwindow.c: moved checks upon focus setting from
+       gtk_window_real_set_focus to gtk_window_set_focus, so we don't
+       emit the signal if unneccessary.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): clear up the old focus
+       containers when grabbing focus on a new widget. this is based on
+       a patch from Alexis Mikhailov, submitted to gtk-list on 4 Nov 1998.
+
+       * gtk/gtkclist.c (gtk_clist_focus_out): set CLIST_CHILD_HAS_FOCUS
+       flag, so we take the buttons into consideration upon the next focus
+       request.
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): fixed an
+       assertment.
+
 Wed Dec  2 17:45:21 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
        * gtk/gtkpixmap.c: Fixes for low-color displays and a slight
index a463ab3b84cdd845a78d28b0cfe8c2261dac36f6..4cb18d030c9ac2eb57a256155500de23e28ce2f3 100644 (file)
@@ -6517,6 +6517,8 @@ gtk_clist_focus_out (GtkWidget     *widget,
   g_return_val_if_fail (event != NULL, FALSE);
 
   GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+  GTK_CLIST_SET_FLAG (widget, CLIST_CHILD_HAS_FOCUS);
+
   gtk_widget_draw_focus (widget);
   
   clist = GTK_CLIST (widget);
@@ -6537,7 +6539,7 @@ gtk_clist_set_focus_child (GtkContainer *container,
   if (child)
     {
       g_return_if_fail (GTK_IS_WIDGET (child));
-      GTK_CLIST_SET_FLAG (GTK_CLIST (container), CLIST_CHILD_HAS_FOCUS);
+      GTK_CLIST_SET_FLAG (container, CLIST_CHILD_HAS_FOCUS);
     }
 
   parent_class->set_focus_child (container, child);
index b42358b2f9595b8315eb90bd4f44fda53e9a0b73..ceb0e83b31c6a829d7c9974b9369c9af917cd5ac 100644 (file)
@@ -1206,13 +1206,13 @@ gtk_container_focus (GtkContainer     *container,
 }
 
 void
-gtk_container_set_focus_child (GtkContainer     *container,
-                              GtkWidget          *widget)
+gtk_container_set_focus_child (GtkContainer *container,
+                              GtkWidget    *widget)
 {
   g_return_if_fail (container != NULL);
   g_return_if_fail (GTK_IS_CONTAINER (container));
   if (widget)
-    g_return_if_fail (GTK_IS_WIDGET (container));
+    g_return_if_fail (GTK_IS_WIDGET (widget));
 
   gtk_signal_emit (GTK_OBJECT (container), container_signals[SET_FOCUS_CHILD], widget);
 }
index 52b4ffd0adb38e6c18fee084d2f72658dfbc6ef2..ac9786fd92593d5a86456ab4b957f482a92dbd0f 100644 (file)
@@ -2833,34 +2833,77 @@ gtk_widget_intersect (GtkWidget    *widget,
  *   results:
  *****************************************/
 
-void
-gtk_widget_grab_focus (GtkWidget *widget)
+static void
+reset_focus_recurse (GtkWidget *widget,
+                    gpointer   data)
 {
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_WIDGET (widget));
+  if (GTK_IS_CONTAINER (widget))
+    {
+      GtkContainer *container;
+
+      container = GTK_CONTAINER (widget);
+      gtk_container_set_focus_child (container, NULL);
+
+      gtk_container_foreach (container,
+                            reset_focus_recurse,
+                            NULL);
+    }
+}
 
-  if (GTK_WIDGET_CAN_FOCUS (widget))
+void
+gtk_widget_grab_focus (GtkWidget *focus_widget)
+{
+  g_return_if_fail (focus_widget != NULL);
+  g_return_if_fail (GTK_IS_WIDGET (focus_widget));
+  
+  if (GTK_WIDGET_CAN_FOCUS (focus_widget))
     {
-      GtkWidget *parent;
-      GtkWidget *child;
-      GtkType window_type;
-      
-      window_type = gtk_window_get_type ();
-      parent = widget->parent;
-      child = widget;
+      GtkWidget *toplevel;
+      GtkWidget *widget;
       
-      while (parent && !gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type))
+      /* clear the current focus setting, break if the current widget
+       * is the focus widget's parent, since containers above that will
+       * be set by the next loop.
+       */
+      toplevel = gtk_widget_get_toplevel (focus_widget);
+      if (GTK_IS_WINDOW (toplevel))
+       {
+         widget = GTK_WINDOW (toplevel)->focus_widget;
+         
+         if (widget == focus_widget)
+           return;
+         
+         if (widget)
+           {
+             while (widget->parent && widget->parent != focus_widget->parent)
+               {
+                 widget = widget->parent;
+                 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
+               }
+           }
+       }
+      else if (toplevel != focus_widget)
        {
-         gtk_container_set_focus_child (GTK_CONTAINER (parent), child);
-         child = parent;
-         parent = parent->parent;
+         /* gtk_widget_grab_focus() operates on a tree without window...
+          * actually, this is very questionable behaviour.
+          */
+         
+         gtk_container_foreach (GTK_CONTAINER (toplevel),
+                                reset_focus_recurse,
+                                NULL);
        }
-      
-      if (parent && gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type))
+
+      /* now propagate the new focus up the widget tree and finally
+       * set it on the window
+       */
+      widget = focus_widget;
+      while (widget->parent)
        {
-         gtk_container_set_focus_child (GTK_CONTAINER (parent), child);
-         gtk_window_set_focus (GTK_WINDOW (parent), widget);
+         gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
+         widget = widget->parent;
        }
+      if (GTK_IS_WINDOW (widget))
+       gtk_window_set_focus (GTK_WINDOW (widget), focus_widget);
     }
 }
 
index 5f74cb5fdd015c56d8b2cf332c95cc7d6f08de29..c46f17c246c005b544b20c3021b002edfb711078 100644 (file)
@@ -79,7 +79,7 @@ static gint gtk_window_focus_out_event    (GtkWidget         *widget,
 static gint gtk_window_client_event      (GtkWidget         *widget,
                                           GdkEventClient    *event);
 static void gtk_window_check_resize       (GtkContainer      *container);
-static void gtk_real_window_set_focus     (GtkWindow         *window,
+static void gtk_window_real_set_focus     (GtkWindow         *window,
                                           GtkWidget         *focus);
 static void gtk_window_move_resize        (GtkWindow         *window);
 static void gtk_window_set_hints          (GtkWidget         *widget,
@@ -184,7 +184,7 @@ gtk_window_class_init (GtkWindowClass *klass)
    
   container_class->check_resize = gtk_window_check_resize;
 
-  klass->set_focus = gtk_real_window_set_focus;
+  klass->set_focus = gtk_window_real_set_focus;
 }
 
 static void
@@ -334,7 +334,16 @@ void
 gtk_window_set_focus (GtkWindow *window,
                      GtkWidget *focus)
 {
-  gtk_signal_emit (GTK_OBJECT (window), window_signals[SET_FOCUS], focus);
+  g_return_if_fail (window != NULL);
+  g_return_if_fail (GTK_IS_WINDOW (window));
+  if (focus)
+    {
+      g_return_if_fail (GTK_IS_WIDGET (focus));
+      g_return_if_fail (GTK_WIDGET_CAN_FOCUS (focus));
+    }
+
+  if (window->focus_widget != focus)
+    gtk_signal_emit (GTK_OBJECT (window), window_signals[SET_FOCUS], focus);
 }
 
 void
@@ -1225,7 +1234,7 @@ gtk_window_move_resize (GtkWindow *window)
 }
 
 static void
-gtk_real_window_set_focus (GtkWindow *window,
+gtk_window_real_set_focus (GtkWindow *window,
                           GtkWidget *focus)
 {
   GdkEventFocus event;
@@ -1233,30 +1242,24 @@ gtk_real_window_set_focus (GtkWindow *window,
   g_return_if_fail (window != NULL);
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  if (focus && !GTK_WIDGET_CAN_FOCUS (focus))
-    return;
-
-  if (window->focus_widget != focus)
+  if (window->focus_widget)
     {
-      if (window->focus_widget)
-       {
-         event.type = GDK_FOCUS_CHANGE;
-         event.window = window->focus_widget->window;
-         event.in = FALSE;
-
-         gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
-       }
-
-      window->focus_widget = focus;
-
-      if (window->focus_widget)
-       {
-         event.type = GDK_FOCUS_CHANGE;
-         event.window = window->focus_widget->window;
-         event.in = TRUE;
-
-         gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
-       }
+      event.type = GDK_FOCUS_CHANGE;
+      event.window = window->focus_widget->window;
+      event.in = FALSE;
+      
+      gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
+    }
+  
+  window->focus_widget = focus;
+  
+  if (window->focus_widget)
+    {
+      event.type = GDK_FOCUS_CHANGE;
+      event.window = window->focus_widget->window;
+      event.in = TRUE;
+      
+      gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
     }
 }